<!DOCTYPE html>
<html>
	<head>
		<title>各种查询参数示例</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<!-- 所有的 css & js 资源 -->
		<link rel="stylesheet" href="https://unpkg.com/element-ui@2.13.0/lib/theme-chalk/index.css">
		<link rel="stylesheet" href="../../static/sa.css">
		<script src="https://unpkg.com/vue@2.6.10/dist/vue.min.js"></script>
		<script src="https://unpkg.com/element-ui@2.13.0/lib/index.js"></script>
		<script src="https://unpkg.com/jquery@3.4.1/dist/jquery.min.js"></script>
		<script src="https://www.layuicdn.com/layer-v3.1.1/layer.js"></script>
		<script src="../../static/sa.js"></script>
	</head>
	<body>
		<div class="vue-box" style="display: none;" :style="'display: block;'">
			<div class="c-panel">
				<!-- ------------- 参数栏 ------------- -->
				<div class="c-title">检索参数</div>
				<el-form>
					
				</el-form>
				
				<!-- ------------- 数据列表 ------------- -->
				<el-table :data="dataList" size="mini">
					<el-table-column label="编号" prop="id"></el-table-column>
					<el-table-column label="名称" prop="name"></el-table-column>
					<el-table-column label="库存" prop="count"></el-table-column>
					<el-table-column label="操作" width="220px">
						<template slot-scope="s">
							<el-button type="text" size="mini" @click="get(s.row)">查看</el-button>
							<el-button type="text" size="mini" @click="update(s.row)">修改</el-button>
							<el-button type="text" size="mini" @click="del(s.row)">删除</el-button>
						</template>
					</el-table-column>
				</el-table>
				<!-- ------------- 分页 ------------- -->
				<div class="page-box">
					<el-pagination background layout="total, prev, pager, next, sizes, jumper" :current-page.sync="p.pageNo"
					 :page-size.sync="p.pageSize" :total="dataList.length" :page-sizes="[1000]" @current-change="f5()" @size-change="f5()">
					</el-pagination>
				</div>
			</div>
		</div>
		<script>
			var app = new Vue({
				el: '.vue-box',
				data: {
					p: { // 查询参数  
						name: '',
						count: '',
						type_id: 0,
						create_time: '',
						start_time: new Date().getFullYear() + '-' + (new Date().getMonth() + 1) + '-1', // 本月一号 
						end_time: new Date().getFullYear() + '-' + (new Date().getMonth() + 1) + '-' + new Date().getDate(), // 本月当日 
						single: 1,
						single2: 1,
						status: 0,
						checkbox_1: true,
						checkbox_2: true,
						checkbox_3: false,
						checkbox_4: false,
						checkbox_5: false,
						checkbox_6: false,
						pageNo: 1,
						pageSize: 1000,
					},
					typeList: [ // 类型数组  
						{
							id: 1,
							name: '类型1'
						},
						{
							id: 2,
							name: '类型2'
						},
						{
							id: 3,
							name: '类型3'
						},
						{
							id: 4,
							name: '类型4'
						},
					],
					dataList: [ // 数据集合
						{
							id: 101,
							name: '苹果',
							count: 3223
						},
						{
							id: 102,
							name: '鸭梨',
							count: 3231
						},
						{
							id: 103,
							name: '香蕉',
							count: 4321
						},
						{
							id: 104,
							name: '西瓜',
							count: 34223
						},
						{
							id: 105,
							name: '菠萝',
							count: 53272
						},
						{
							id: 106,
							name: '辣椒',
							count: 20000
						},
						{
							id: 107,
							name: '冬瓜',
							count: 50000
						},
						{
							id: 108,
							name: '西红柿',
							count: 99999
						},
						{
							id: 109,
							name: '火龙果',
							count: 58989
						},
						{
							id: 110,
							name: '红烧鸡脖子',
							count: 22345
						},
					],
				},
				methods: {
					// 刷新
					f5: function() {
						//this.$message(JSON.stringify(this.p))
						sa.ajax2('/goods/getList', this.p, function(res) {
							// this.dataList = res.data;	// 数据
						}.bind(this));
					},
					// 查看
					get: function(data) {
						var str = '<div>';
						str += '<p>编号：' + data.id + '</p>';
						str += '<p>名称：' + data.name + '</p>';
						str += '<p>库存：' + data.count + '</p>';
						str += '</div>';
						sa.alert(str);
					},
					// 修改
					update: function(data) {
						// sa.msg('你点击了id=' + data.id + '的修改按钮');
						sa.prompt('修改库存', function(pass, index) {
							if (isNaN(pass)) {
								return sa.error('请输入一个数字')
							}
							sa.ajax2('/data/update', {
								id: data.id,
								count: data.count
							}, function(res) {
								data.count = pass;
								sa.ok('修改成功');
							})
						}, 0, data.count);
					},
					// 删除
					del: function(data) {
						sa.confirm('是否删除，此操作不可撤销', function() {
							sa.ajax2('/goods/delete?id=' + data.id, function(res) {
								sa.arrayDelete(this.dataList, data);
								sa.ok('删除成功');
							}.bind(this))
						}.bind(this));
					},
				},
				created: function() {
					this.f5();
					sa.onInputEnter(); // 监听输入框的回车事件，执行查询  
					this.$notify.info({
						title: '消息',
						message: '本页面展示各种检索参数，以便完成强大的列表查询'
					});
				}
			})
		</script>
	</body>
</html>
